<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>代理管理</title>
<meta name="decorator" content="default" />
<script type="text/javascript">
	$(document).ready(
			function() {
				//$("#name").focus();
				$("#inputForm")
						.validate(
								{
									submitHandler : function(form) {
										loading('正在提交，请稍等...');
										form.submit();
									},
									errorContainer : "#messageBox",
									errorPlacement : function(error, element) {
										$("#messageBox").text("输入有误，请先更正。");
										if (element.is(":checkbox")
												|| element.is(":radio")
												|| element.parent().is(
														".input-append")) {
											error.appendTo(element.parent()
													.parent());
										} else {
											error.insertAfter(element);
										}
									}
								});
				loadAll('${institution.province}', '${institution.county}');
				loadAuthenticates();
				init1();
			});

	function loadAll(officeId, serverAreaId) {
		if (officeId == null) {
			officeId = $('#institution.province').val();
		}
		loadSheng();
	}

	//加载省
	function loadSheng() {
		var shengId = '${institution.province}';
		var quanName = '';
		var url = "";
		var parameter = {};
		//服务预约列表信息
		url = "${ctx}/c/getSheng";
		$
				.ajax({
					type : "post",
					url : url,
					dataType : 'json',
					data : parameter,
					success : function(data, textStatus) {
						var data = data.data;
						var html = "";
						var m = 0;
						for (var i = 0; i < data.length; i++) {
							var p = data[i];
							if (shengId == p.id) {
								quanName = p.name;
								m = i;
								html = html
										+ '<option value="'+p.id+'" selected="selected" >'
										+ p.name + '</option>';
							} else
								html = html + '<option value="'+p.id+'" >'
										+ p.name + '</option>';
						}
						$("#province").html(html);
						$("#province").get(0).selectedIndex = m;
						$("div.select2-container")
								.each(
										function() {
											var p = $(this).context;
											var pid = p.id;
											if (pid.indexOf('province') > 0) {
												p.firstElementChild.firstElementChild.innerText = quanName;
											}
										});
						outputCity();
					},
					complete : function(XMLHttpRequest, textStatus) {
					},
					error : function() {
					}
				});
	};
	//加载市
	function loadCity(officeId) {
		var cityId = '${institution.city}';
		var quanName = '';
		var url = "";
		var parameter = {};
		//服务预约列表信息
		url = "${ctx}/c/getCity";
		parameter.parentId = officeId;//$('#officeIdId').val();
		$
				.ajax({
					type : "post",
					url : url,
					dataType : 'json',
					data : parameter,
					success : function(data, textStatus) {
						var data = data.data;
						var html = "";
						var m = 0;
						for (var i = 0; i < data.length; i++) {
							var p = data[i];
							if (cityId == p.id) {
								quanName = p.name;
								m = i;
								html = html
										+ '<option value="'+p.id+'" selected="selected" >'
										+ p.name + '</option>';
							} else
								html = html + '<option value="'+p.id+'" >'
										+ p.name + '</option>';
						}
						$("#city").html(html);
						$("#city").get(0).selectedIndex = m;
						$("div.select2-container")
								.each(
										function() {
											var p = $(this).context;
											var pid = p.id;
											if (pid.indexOf('city') > 0) {
												p.firstElementChild.firstElementChild.innerText = quanName;
											}
										});
						outputCouny();
					},
					complete : function(XMLHttpRequest, textStatus) {
					},
					error : function() {
					}
				});
	};

	//加载县/区
	function loadCountry(officeId) {
		var countyId = '${institution.county}';
		var quanName = '';
		var url = "";
		var parameter = {};
		//服务预约列表信息
		url = "${ctx}/c/getCountry";
		parameter.parentId = officeId;//
		$
				.ajax({
					type : "post",
					url : url,
					dataType : 'json',
					data : parameter,
					success : function(data, textStatus) {
						var data = data.data;
						var html = "";
						var m = 0;
						for (var i = 0; i < data.length; i++) {
							var p = data[i];
							if (countyId == p.id) {
								quanName = p.name;
								m = i;
								html = html
										+ '<option value="'+p.id+'" selected="selected" >'
										+ p.name + '</option>';
							} else
								html = html + '<option value="'+p.id+'" >'
										+ p.name + '</option>';
						}
						$("#county").html(html);
						$("#county").get(0).selectedIndex = m;
						$("div.select2-container")
								.each(
										function() {
											var p = $(this).context;
											var pid = p.id;
											if (pid.indexOf('county') > 0) {
												p.firstElementChild.firstElementChild.innerText = quanName;
											}
										});
					},
					complete : function(XMLHttpRequest, textStatus) {
					},
					error : function() {
					}
				});
	};

	function outputCity() {
		loadCity($("#province").val());
	}

	function outputCouny() {
		loadCountry($("#city").val());
	}

	function init1() {
		var ids = strcondition.split(',');
		var idName = strconditionName.split(',');
	}

	function initSchool(name) {
		var s = '<li class="select2-search-choice"><div>'
				+ name
				+ '</div><a href="#" onclick="return false;" class="select2-search-choice-close" tabindex="-1"></a></li>'
		return s;
	}

	function loadAuthenticates() {
		var shopTagS = '${institution.authenticates}';
		if (shopTagS != null) {
			var shopTagA = shopTagS.split(",");
			for (var i = 0; i < shopTagA.length; i++) {
				var o = shopTagA[i];
				var m = o;
				$("input[name^='authenticates']").each(function(i, o) {
					v = $(o).val();
					if (v == m) {
						$(o).attr("checked", 'true');
					}
				});
			}
		}
	}
</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/sys/agent/list">代理列表</a></li>
		<li><a href="${ctx}/sys/agent/form?id=${institution.id}">代理${not empty institution.id?'修改':'添加'}</a></li>
	</ul>
	<br />
	<form:form id="inputForm" modelAttribute="institution"
		action="${ctx}/sys/agent/save" method="post" class="form-horizontal">
		<form:hidden path="id" />
		<sys:message content="${message}" />
		<div class="control-group">
			<label class="control-label">企业名称：</label>
			<div class="controls">
				<form:input path="institutionName" htmlEscape="false"
					maxlength="255" class="input-xlarge required" />
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">地址：</label>
			<div class="controls">
				<form:input path="address" htmlEscape="false" maxlength="255"
					class="input-xlarge " />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">省：</label>
			<div class="controls">
				<form:select path="province" class="input-xlarge "
					onchange="outputCity()">
					<form:options itemLabel="name" itemValue="id" htmlEscape="false" />
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">市：</label>
			<div class="controls">
				<form:select path="city" class="input-xlarge "
					onchange="outputCouny()">
					<form:options itemLabel="name" itemValue="id" htmlEscape="false" />
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">县/区：</label>
			<div class="controls">
				<form:select path="county" class="input-xlarge ">
					<form:options itemLabel="name" itemValue="id" htmlEscape="false" />
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">企业介绍：</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="4"
					maxlength="255" class="input-xxlarge " />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">领域：</label>
			<div class="controls">
				<form:input path="area" htmlEscape="false" class="input-xxlarge " />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">企业LOGO：</label>
			<div class="controls">
				<form:hidden path="logo" htmlEscape="false" maxlength="255"
					class="input-xlarge" />
				<sys:ckImage input="logo" type="images" uploadPath="/cms/site" />
			</div>
		</div>
		<%-- <div class="control-group">
			<label class="control-label">所在校区：</label>
			<div class="controls">
				<form:select id="schoolId" path="schoolId" class="input-xlarge" multiple="true">
					<form:options items="${fns:getSchoolList()}" itemLabel="schoolName" itemValue="id" htmlEscape="false"/>
				</form:select>
			</div>
		</div> --%>
		<div class="control-group">
			<label class="control-label">资质与证书：</label>
			<div class="controls">
				<div class="row">
					<div class="span3">
						<form:hidden path="certificate1" htmlEscape="false"
							maxlength="255" class="input-xlarge" />
						<sys:ckImage input="certificate1" type="images"
							uploadPath="/cms/site" />
					</div>
					<div class="span3">
						<form:hidden path="certificate2" htmlEscape="false"
							maxlength="255" class="input-xlarge" />
						<sys:ckImage input="certificate2" type="images"
							uploadPath="/cms/site" />
					</div>
					<div class="span3">
						<form:hidden path="certificate3" htmlEscape="false"
							maxlength="255" class="input-xlarge" />
						<sys:ckImage input="certificate3" type="images"
							uploadPath="/cms/site" />
					</div>
				</div>
				<div class="row">
					<div class="span3">
						<form:hidden path="certificate4" htmlEscape="false"
							maxlength="255" class="input-xlarge" />
						<sys:ckImage input="certificate4" type="images"
							uploadPath="/cms/site" />
					</div>
					<div class="span3">
						<form:hidden path="certificate5" htmlEscape="false"
							maxlength="255" class="input-xlarge" />
						<sys:ckImage input="certificate5" type="images"
							uploadPath="/cms/site" />
					</div>
					<div class="span3">
						<form:hidden path="certificate6" htmlEscape="false"
							maxlength="255" class="input-xlarge" />
						<sys:ckImage input="certificate6" type="images"
							uploadPath="/cms/site" />
					</div>
				</div>
			</div>
		</div>
		<%-- <div class="control-group">
			<label class="control-label">环境图片：</label>
			<div class="controls">
			<div class="row">
				  <div class="span3">
				  		<form:hidden path="environment1" htmlEscape="false" maxlength="255" class="input-xlarge"/>
						<sys:ckImage input="environment1" type="images" uploadPath="/cms/site"/>
				  </div>
				  <div class="span3">
				  		<form:hidden path="environment2" htmlEscape="false" maxlength="255" class="input-xlarge"/>
						<sys:ckImage input="environment2" type="images" uploadPath="/cms/site"/>
				  </div>
				  <div class="span3">
				  		<form:hidden path="environment3" htmlEscape="false" maxlength="255" class="input-xlarge"/>
						<sys:ckImage input="environment3" type="images" uploadPath="/cms/site"/>
				  </div>
			</div>
			<div class="row">
				   <div class="span3">
				  		<form:hidden path="environment4" htmlEscape="false" maxlength="255" class="input-xlarge"/>
						<sys:ckImage input="environment4" type="images" uploadPath="/cms/site"/>
				  </div>
				  <div class="span3">
				  		<form:hidden path="environment5" htmlEscape="false" maxlength="255" class="input-xlarge"/>
						<sys:ckImage input="environment5" type="images" uploadPath="/cms/site"/>
				  </div>
				  <div class="span3">
				  		<form:hidden path="environment6" htmlEscape="false" maxlength="255" class="input-xlarge"/>
						<sys:ckImage input="environment6" type="images" uploadPath="/cms/site"/>
				  </div>
			</div>
			</div>
		    </div>
		</div>
		<div class="control-group">
			<label class="control-label">设备图片：</label>
			<div class="controls">
					<div class="row">
				  <div class="span3">
				  		<form:hidden path="equipment1" htmlEscape="false" maxlength="255" class="input-xlarge"/>
						<sys:ckImage input="equipment1" type="images" uploadPath="/cms/site"/>
				  </div>
				  <div class="span3">
				  		<form:hidden path="equipment2" htmlEscape="false" maxlength="255" class="input-xlarge"/>
						<sys:ckImage input="equipment2" type="images" uploadPath="/cms/site"/>
				  </div>
				  <div class="span3">
				  		<form:hidden path="equipment3" htmlEscape="false" maxlength="255" class="input-xlarge"/>
						<sys:ckImage input="equipment3" type="images" uploadPath="/cms/site"/>
				  </div>
			</div>
			<div class="row">
				   <div class="span3">
				  		<form:hidden path="equipment4" htmlEscape="false" maxlength="255" class="input-xlarge"/>
						<sys:ckImage input="equipment4" type="images" uploadPath="/cms/site"/>
				  </div>
				  <div class="span3">
				  		<form:hidden path="equipment5" htmlEscape="false" maxlength="255" class="input-xlarge"/>
						<sys:ckImage input="equipment5" type="images" uploadPath="/cms/site"/>
				  </div>
				  <div class="span3">
				  		<form:hidden path="equipment6" htmlEscape="false" maxlength="255" class="input-xlarge"/>
						<sys:ckImage input="equipment6" type="images" uploadPath="/cms/site"/>
				  </div>
			</div>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">认证情况：</label>
			<div class="controls">
				<form:checkboxes items="${fns:getDictList('authenticates')}" path="authenticates" itemLabel="label" itemValue="value" htmlEscape="false"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div> --%>
		<div class="form-actions">
			<input id="btnSubmit" class="btn btn-primary" type="submit"
				value="保 存" />&nbsp; <input id="btnCancel" class="btn" type="button"
				value="返 回" onclick="history.go(-1)" />
		</div>
	</form:form>
</body>
</html>